package com.yh.csx.etl.scheduler;

import javax.annotation.PreDestroy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.yh.csx.etl.worker.EtlWorkerManager;

/**
 * XXL job
 * 
 * @author Robin.Wang
 * @date 2019-01-05
 * @version 1.0.0
 */

@JobHandler("etlHandler")
public class EtlXxljobScheduler extends IJobHandler {

    private static final Logger log = LoggerFactory.getLogger(EtlXxljobScheduler.class);

    @Autowired
    private EtlWorkerManager workManager;

    @PreDestroy
    public synchronized void destroy() {
        workManager.stop();
        log.info("xxl job etlHandler stoped");
    }

    @Override
    public ReturnT<String> execute(String param) throws Exception {
        log.info("xxl job etlHandler start...");
        // workManager=ContextUtils.getBean(EtlWorkerManager.class,true);
        workManager.init();
        workManager.start();
        return ReturnT.SUCCESS;
    }
}
